/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package regulatoryInteractionsStats.yeast;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Arrays;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.FileUtils;

/**
 *
 * @author jamie
 */
public class RegultoryInteractionSet {

    private HashSet<String> regulatoryInteractions = new HashSet<String>();

    private File regulatoryInteractionsFile = new File("/Users/jamie/Dropbox/monkeys/yeast/regulatoryInteractions.txt");
    private YeastGeneLibrary yeastGeneLibrary;
    private TreeSet<String> genes = new TreeSet<String>();
    
    public RegultoryInteractionSet(YeastGeneLibrary yeastGeneLibrary) {
        this.yeastGeneLibrary = yeastGeneLibrary;
        populateInteractions();
    }

    public void populateInteractions(){
        BufferedReader reader = FileUtils.getBufferedReader(regulatoryInteractionsFile);
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                String[] split = line.split("\t");
                YeastGene yg1 = yeastGeneLibrary.getGeneBySymbol(split[0]);
                YeastGene yg2 = yeastGeneLibrary.getGeneBySymbol(split[2]);
                if(yg1!=null && yg2!=null){
                    String[] symbols = new String[2];
                    symbols[0] = yg1.getSymbol();
                    symbols[1] = yg2.getSymbol();
                    Arrays.sort(symbols);
                    String interactionString = symbols[0]+":"+symbols[1];
                    if(!regulatoryInteractions.contains(interactionString)){
                        regulatoryInteractions.add(interactionString);
                    }
                    if(!genes.contains(symbols[0])){
                        genes.add(symbols[0]);
                    }
                    if(!genes.contains(symbols[1])){
                        genes.add(symbols[1]);
                    }
                }
            }
            reader.close();
        } catch (IOException ex) {
            Logger.getLogger(RegultoryInteractionSet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public HashSet<String> getRegulatoryInteractions() {
        return regulatoryInteractions;
    }

    public TreeSet<String> getGenes() {
        return genes;
    }

    public YeastGeneLibrary getYeastGeneLibrary() {
        return yeastGeneLibrary;
    }

    

    

    

}
